1. Field of the Art
The present disclosure relates generally to the field of data processing in dynamic programming languages. Specifically presented are methods and systems for automatically testing methods and other functions using hot code swapping in JavaScript® and other ECMAScript-compatible languages.
2. Description of the Related Art
Computer programming languages have developed rapidly over the years. Modern computer languages typically include provisions for declaring classes, from which objects are instantiated. This allows object-oriented approaches to programming. Object-oriented programming commonly allows encapsulation of code so that the code is modular and reusable for other programs as well as easier to abstract in regard to real-world things.
In computer programming, functions include subroutines that typically perform processing tasks. Such functions can be called from another part of a software program. Functions can also include main routines (e.g., main( ) in the C programming language) that are initially called upon program execution. A function can have explicit inputs that are often called arguments, although some functions have no explicit inputs. Functions can be used to return a value (or multiple values in some instances), change variables, or perform other processing.
A function that is anchored to a class or object is often called a method. The object to which the method is anchored is sometimes called a context, or ‘this.’ object in JavaScript. The internal variables, properties, and other settings of the context are sometimes called a “context state.” Often, a method of an object is called in order to change the object's context state. For example, to set property ‘X’ of object ‘obj’, a method such as obj.setX( ) can be called. The same property could be read by calling obj.getX( ).
Although many modern programming languages are designed to be compiled before they execute, other modern programming languages are interpreted on the fly during program execution. Some of the interpreted languages also belong to the family of “dynamic programming languages” in that their source code can be added to, objects and definitions can be extended, and/or their type systems can be modified during program execution (i.e., at runtime). The JavaScript® programming language is one example of a dynamic programming language. JavaScript is sometimes referred to as a dialect of ECMAScript.
ECMAScript is a computer programming scripting language complying with Ecma International's ECMA-262 specification and International Organization for Standardization (ISO)/International Electrotechnical Commission (IEC) 16262. Ecma was formerly known as the European Computer Manufacturers Association (ECMA). ECMAScripts include Netscape/Sun/Oracle JavaScript, Microsoft JScript, and Adobe ActionScript.
Testing of JavaScript® programs sometimes involves testing each method of each object individually, at the unit level. Thus, a method that horizontally centers a rectangle object with the center of a display is sometimes tested in isolation from all other methods of the object, including a method that vertically centers the rectangle object on the display. Testing can involve writing programs that automatically test the method. Although testing each and every method separately with automated programs can minimize errors later on, it can be very tedious for programmers to test at the lowest levels for hundreds or thousands of methods of many classes/objects in large programs. Test-driven development techniques take testing further so that automated test programs take a high priority.
Software development methodologies like Extreme Programming have popularized test driven development techniques. In particular, unit testing has met a fairly wide adoption thanks to frameworks like JUnit. However in many frameworks and languages, writing tests can be a cumbersome and time-consuming process. For example, it can be difficult to write a unit test for a complex algorithm.
Unit testing usually means focusing on one unit of code; references to all code “external” to that unit should be abstracted. Abstracting the ‘external’ code often requires extra work in order to implement so-called mock objects to represent it.
There exists a need in the art for better techniques to more easily test functions and methods, especially in widely supported, object-oriented, dynamic programming languages such as JavaScript.